package com.mr.flowbean.partition;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
/*
 * 1.统计手机号（String）的上行(Long)，下行(Long)，总流量 (Long)
 * 手机号为key,Bean{上行(Long)，下行(Long)，总流量 (Long)}为value
 */

public class FlowBeanMapper extends Mapper<LongWritable, Text, Text, FlowBean>{

	private Text out_key = new Text();
	private FlowBean out_value = new FlowBean();

	// 1	13736230513	192.196.100.1	www.atguigu.com	2481	24681	200
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, FlowBean>.Context context)
			throws IOException, InterruptedException {


		String[] words = value.toString().split("\t");

		// 封装手机号
		out_key.set(words[1]);

		// 封装上行流量（上行流量的值有可能为空，所以倒着取）
		out_value.setUpFlow(Long.parseLong(words[words.length - 3]));

		// 封装下行流量
		out_value.setDownFlow(Long.parseLong(words[words.length - 2]));

		// 写出key-value，总流量先不计算
		context.write(out_key, out_value);

	}


}
